package com.asset.salesforce.view;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;


public class HeaderAndFooter extends PdfPageEventHelper {

public BaseFont helv;

@Override
public void onEndPage(PdfWriter writer, Document document) {
try {
Rectangle page = document.getPageSize();
PdfPTable footTable = getFooterSignatures();
footTable.setTotalWidth(page.getWidth()- document.leftMargin() - document.rightMargin());
footTable.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin() + 20,     writer.getDirectContent());
} catch (DocumentException ex) {
ex.printStackTrace();
}
}

private PdfPTable getFooterSignatures() throws DocumentException {
Font fontStyleFooters = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
PdfPTable footTable = new PdfPTable(2);
footTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
footTable.setWidths(new int[]{50, 50});
footTable.setWidthPercentage(100);
footTable.getDefaultCell().setPadding(2);
footTable.getDefaultCell().setBorderWidth(0);
footTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

PdfPCell cell5 = new PdfPCell(new Phrase("Office:", FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD)));
cell5.setBorder(Rectangle.NO_BORDER);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("Address:", FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD)));
cell5.setBorder(Rectangle.NO_BORDER);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("(202) 267 21 993", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("3 Ibrahim Abo ElNaga St., Nasr City, Cairo, Egypt", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("01020010751", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("010220010752", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
footTable.addCell(cell5);
cell5 = new PdfPCell(new Phrase("010220010753", fontStyleFooters));
cell5.setBorder(Rectangle.NO_BORDER);
cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
footTable.addCell(cell5);
return footTable;
}
}